// 车险保存
import Vue from 'vue'
import  route from '@/router/index'
import {store} from '@/store/index'
let vueObj:any = new Vue();

const save = {
    title: '保存订单',
    icon: 'icon-save',
    pag: 'formSave',
    fn (){
        

        // 提交是否为新建订单
        let orderId = store.state['carFormStore']['orderData']['Did'];

        store.dispatch('request', {
            url: 'patch/orders/id',
            data:{}
        }).then(success =>{

            // 成功提示
            if(success){
                vueObj.$Notice.success({
                    title: '订单保存成功',
                })  
            }
            
          return success  
            
        }).then(success =>{

            // 保存失败, 或非新建订单时, 不修改订单状态
            if(success &&  !orderId){
                store.dispatch('request', {
                    url: 'patch/order/id/status',
                    data: {
                        currentAction: '保存'
                    }
                })

            }

            return success;
            
        })

    }
    
}

export default save